#include "RigidBody.h"

#include "Scene/Scene.h"
#include "Physics/PhysicalScene.h"


void RRigidBody::OnBeginPlay()
{
    Super::OnBeginPlay();

    GetScene()->GetPhysicalScene()->RegisterRigidBody(this);
}

void RRigidBody::OnEndPlay()
{
    GetScene()->GetPhysicalScene()->UnregisterRigidBody(this);

    Super::OnEndPlay();
}


void RRigidBody::SetInertiaVector(const SVec3 &InInertiaVector)
{
    InertiaVector=InInertiaVector;

    //根据惯性向量计算惯性张量
    //惯性张量是一个对称矩阵
    //对角线元素为物体绕着这个轴旋转的惯性
    //非对角线元素为物体绕着这两个轴旋转的惯性
    InertiaTensor=SMatrix3x3::Zero;
    InertiaTensor.At(0,0)= InertiaVector.X;
    InertiaTensor.At(1,1) = InertiaVector.Y;
    InertiaTensor.At(2,2) = InertiaVector.Z;
    //其余元素为0

    //计算惯性张量的逆
    InertiaTensorInverse=InertiaTensor.Inverse();

    

    
}

SVec3 RRigidBody::GetInertiaVector() const
{
    return InertiaVector;
}
